﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OutlookTags
{
    public class WindowClassEnumerator : IEnumerable<IntPtr>
    {
        IntPtr _parrent;
        string _className;
        string _title;

        public WindowClassEnumerator(IntPtr parrent, string className, string title)
        {
            _parrent = parrent;
            _className = className;
            _title = title;
        }
        #region IEnumerable<IntPtr> Members

        public IEnumerator<IntPtr> GetEnumerator()
        {
            IntPtr previouse = IntPtr.Zero;
            do
            {
                previouse = SafeNativeMethods.FindWindowEx(_parrent, previouse, _className, _title);
                if (previouse != IntPtr.Zero)
                    yield return previouse;
                else
                    break;
            } while (true);            
        }

        #endregion

        #region IEnumerable Members

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        #endregion
    }
}
